package gspushmq.v1.produce.job.sys;

import ggframework.mongodb.BasicDBObject;
import ggframework.mongodb.DBCollection;
import ggframework.mongodb.DBObject;
import gspushmq.model.*;
import gspushmq.util.*;
import gspushmq.v1.consumer.core.MessageQueue;
import gspushmq.v1.produce.job.core.GGServiceJob;

import java.util.Date;
import java.util.Map;

/**
 * @Description 360周报，每周69点半检测数据库中是否有最新记录，有则生产信号通知
 *
 * @Author chengsj
 * @Date 2018/11/29 11:09
 * @Version 1.0
 * @company 上海朝阳永续信息技术有限公司
 * @copyright (c) 2015 SunTime Co'Ltd Inc. All rights reserved.
 **/
public class GGWeeklyreportJob extends GGServiceJob {

    @Override
    public String setJobName() {
        return "--360周报--";
    }

    @Override
    public void doServiceJob(Map<String, Object> args) {
        DBCollection collection = MongoUtil.getFtStrategyCollection("cp_360_stock_label");
        Date lastExchangeDate = GGDate.getLastExchangeData(new Date());
        if (lastExchangeDate == null){
            GGLogger.error(getClass(),"本周最后一个交易日获取失败!");
            return;
        }

        Date startDate = DateUtil.getWeekMonday(lastExchangeDate);
        Date endDate   = DateUtil.getWeekFriday(lastExchangeDate);

        DBObject query = new BasicDBObject("con_date",lastExchangeDate);
        long count = collection.count(query);
        if (count >0){
            //dataMessage对象uuid自动生成
            Data data = new DataMessage();
            String pattn = "yyyy-MM-dd";
            data.setTitle("自选股360周报("+DateUtil.dateToString(startDate,pattn)+"至"+DateUtil.dateToString(endDate,pattn)+")");

            data.setContent("截止"+DateUtil.dateToString(endDate,pattn)+",您的自选股360周报已更新！\n点击查看-->");

            data.setMqType(PrefixEnum.WREPORT360.getMqType());
            data.setMqSubType(PrefixEnum.WREPORT360.getMqSubType());
            data.setCrowdType(ConsumerWays.ALL.getWay());
            data.setCrowdValue(ConsumerWays.ALL.getWay());
            //2弹窗
            data.setLinkType(LinkEnum.WINDOW.getLinkType());
            data.setModule(SkipConstant.WREPORT_360_LINK_URL);
            data.setLinkUrl(SkipConstant.WREPORT_360_LINK_URL);

            //保留到下周6
            Date now  = new Date();
            data.setStartDate(now);
            data.setExpireDate(DateUtil.getAfterDate(now,7));

            //入库
            SysUtil.sendToMongo(data);
            //入队列
            MessageQueue.messageQueue.add(data);
            //日志
            GGLogger.info(getClass(),"--360周报--："+startDate+"/"+endDate+"生产成功！");
        }
    }
}

